"""
跑腿代办管理后台配置
"""

from django.contrib import admin
from django.utils.html import format_html
from .models import ErrandRunner, ErrandOrder


@admin.register(ErrandRunner)
class ErrandRunnerAdmin(admin.ModelAdmin):
    """
    跑腿员管理
    """
    
    list_display = [
        'user', 'status', 'is_verified', 'total_orders', 
        'completed_orders', 'rating', 'created_at'
    ]
    
    list_filter = ['status', 'is_verified', 'created_at']
    
    search_fields = ['user__username', 'user__nickname']
    
    ordering = ['-total_orders', 'user__username']
    
    fieldsets = (
        ('用户信息', {
            'fields': ('user',)
        }),
        ('跑腿员信息', {
            'fields': ('status', 'is_verified')
        }),
        ('服务信息', {
            'fields': ('service_areas', 'service_types')
        }),
        ('统计信息', {
            'fields': ('total_orders', 'completed_orders', 'cancelled_orders', 'total_earnings', 'rating')
        }),
    )


@admin.register(ErrandOrder)
class ErrandOrderAdmin(admin.ModelAdmin):
    """
    跑腿订单管理
    """
    
    list_display = [
        'order_number', 'customer', 'runner', 'order_type', 
        'status', 'base_fee', 'created_at'
    ]
    
    list_filter = ['status', 'order_type', 'created_at']
    
    search_fields = ['order_number', 'title', 'customer__username', 'runner__user__username']
    
    ordering = ['-created_at']
    
    fieldsets = (
        ('基本信息', {
            'fields': ('order_number', 'customer', 'runner')
        }),
        ('订单信息', {
            'fields': ('order_type', 'status', 'title', 'description')
        }),
        ('地址信息', {
            'fields': ('pickup_address', 'delivery_address')
        }),
        ('联系信息', {
            'fields': ('customer_phone',)
        }),
        ('费用信息', {
            'fields': ('base_fee', 'tips', 'total_fee')
        }),
    )
